package com.naton.common.callback;

import android.view.View;

/**
 * @time: 2022/1/18
 * @author: lifuling
 * @version: v1.0
 * @file_desc: 保证同一按钮在2秒内只会响应一次点击事件
 */
public abstract class OnSingleClickListener implements View.OnClickListener{

    //两次点击按钮之间的间隔，目前为1000ms
    private static final int MIN_CLICK_DELAY_TIME = 2000;
    private long lastClickTime;

    public abstract void onSingleClick(View view);
    @Override
    public void onClick(View view) {
        long curClickTime = System.currentTimeMillis();
        if ((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
            lastClickTime = curClickTime;
            onSingleClick(view);
        }
    }
}
